﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using PickGold.Callers;

namespace PickGold.Arguments
{
	/// <summary>
	/// 委托调用参数
	/// </summary>
	public class CAsyncCallEventArgs : EventArgs
	{
		internal int InnerTimeout;
		internal object InnerAsyncKey;
		internal IDelegate InnerHandler;
		internal CRemoteProcedureCallAsyncResult InnerResult;

		/// <summary>
		/// 构造一参数实例
		/// </summary>
		/// <param name="handler">委托</param>
		internal CAsyncCallEventArgs(IDelegate handler)
		{
			this.InnerHandler = handler;
		}

		/// <summary>
		/// 获取或设置异步操作超时时间（毫秒）
		/// </summary>
		public int Timeout
		{
			set
			{
				this.InnerTimeout = value;
			}
			get
			{
				return this.InnerTimeout;
			}
		}

		/// <summary>
		/// 委托
		/// </summary>
		public IDelegate Handler
		{
			get
			{
				return this.InnerHandler;
			}
		}

		/// <summary>
		/// 设置异步操作状态键，值在所有并发调用中必须唯一，如果不调用或为空则表示异步操作失败。
		/// </summary>
		/// <param name="value">异步操作状态键，如果表示异步操作失败可不调用或为空。</param>
		public void SetAsyncKey(object value)
		{
			if (this.InnerAsyncKey == value)
				return;

			CRemoteProcedureCall.SetInvokeKey(this, value);
			this.InnerAsyncKey = value;
		}
	}
}
